<?php

namespace App\Http\Controllers\Admin;

use App\Topic;
use Illuminate\Http\Request;

class TopicController extends Controller
{
    //专题页面
    public function index()
    {
        $topics = Topic::all();
        return view('admin.topic.index', compact('topics'));
    }

    //专题增加页
    public function create()
    {
        return view('admin.topic.create');
    }

    //专题增加行为
    public function store()
    {
        $this->validate(request(), [
            'name' => 'required|min:3'
        ]);

        Topic::create(request(['name']));

        return redirect('/admin/topics');
    }

    //专题删除
    public function destroy(Topic $topic)
    {
        $topic->delete();
        return [
            'error' => 0,
            'msg' => '',
        ];
    }
}
